package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.MaDetailActivity;
import com.example.administrator.yuejian_2.bean.MasterListBean;
import com.example.administrator.yuejian_2.viewholder.MaListVH;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/2.
 */

public class MaListAdapter extends RecyclerView.Adapter {
    private List<MasterListBean> maList = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public MaListAdapter(Context context,List<MasterListBean> maList){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.maList.addAll(maList);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_ma,parent,false);
        MaListVH holder = new MaListVH(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MaListVH masterholder = (MaListVH) holder;
        MasterListBean masterList = maList.get(position);

        String mastername = masterList.getC_name();
        masterholder.maname.setText(mastername);

        String mastertype = masterList.getC_type();
        masterholder.matype.setText(mastertype+"大师");

        int likesum = masterList.getLiked();
        String sum = String.valueOf(likesum);
        masterholder.malikesum.setText(sum);

        String pic = masterList.getC_pic();
        if (!pic.equals(""))
            Picasso.with(context)
                    .load("http://10.0.2.2/YueJian16/Public/photo/"+pic)
                    .into(masterholder.mapic);

        final int mid = masterList.getC_id();
        masterholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, MaDetailActivity.class);
                intent.putExtra("mid",mid);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {

        return maList.size();
    }
}
